package ntd.util.frame.javacv.vlc;

import lombok.Data;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;

@Data
public class VlcContext {
    //这两个参数可加可不加，如果想要通过窗口展示视频画面，就不加， 如果不想显示视频画面，就加上
    private static String[] VLC_ARGS = {"--vout", "dummy"};

    MediaPlayerFactory mediaPlayerFactory;

    MediaPlayer headlessMediaPlayer;

    public static VlcContext init() {
        VlcContext vlcContext = new VlcContext();
        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(VLC_ARGS);
        vlcContext.setMediaPlayerFactory(mediaPlayerFactory);
        vlcContext.setHeadlessMediaPlayer(mediaPlayerFactory.newHeadlessMediaPlayer());
        return vlcContext;
    }

    /**
     * 释放资源
     */
    public void close() {
        headlessMediaPlayer.stop();
        headlessMediaPlayer.release();
        mediaPlayerFactory.release();
    }
}
